﻿using Controller;
using HBase;
using hCommand;
using Net.http;
using System;
using System.Collections.Generic;

namespace Persistence {
    public class InLocCase : InLocBSEngine<CoreStock>
    { 
        public int eigen = 0; 
        protected override void before( )
        {
            string sql = @"select * from Core_stock where  status >={0} and status<={1}   and box_Code=@boxCode";
            sql = HUtil.s(sql, StockStatus.库外, StockStatus.库存);
            List<CoreStock> stockList = query<CoreStock>(sql, new
            {
                boxCode
            });
            if (stockList.Count > 1)
            {
                throw new Exception(boxCode + "对应托盘过多");
            }
            else if (stockList.Count == 1)
            {
                string update = @"update Core_stock set eigen=@eigen where  id=@id";
                CoreStock stock = stockList[0];
                stock.eigen = eigen; 
               exec(update,stock);
            
            }
            
        }
        protected override string stnToCrane(long loc) {
            if (I18nConfig.isLoc(loc)) {
                return (loc + 300000) / 400000 + "号垛机" + loc;
            } 
            return loc.ToString();
        }
        

        protected override TaskParamType getType(int src)
        {
            return TaskParamType.托盘搬运;
        }
        
       
        protected override TransRes afterIntask(  CoreStock cs, CoreWhLoc loc)
        {
            String sql = "update core_stock_det set change_time=sgj_get_sys_now, status={0}  where pid=@stockId  and  status={1}";
            sql = HUtil.s(sql, StockDetailStatus.入库中, StockDetailStatus.库外);
            int c = exec(sql, new { stockId = cs.id });
            return new TransRes();
        }

      

       
    }
}
